#!/usr/bin/env bash
osascript \
    -e 'tell application "Terminal"' \
    -e 'set position of front window to {1, 1}' \
    -e 'end tell'
opt1="Display Live Stream"
opt2="Record Live Stream"
opt3="Play and Record Live Stream"
opt4="Convert Recorded Stream to MP4"
streammenu=$(zenity  --list  --title "Video Stream Tool" --radiolist  --column "" --column "" TRUE "$opt1" FALSE "$opt2" FALSE "$opt3" FALSE "$opt4" --height=400 --width=300)
case $streammenu in
$opt1 )
url=$(zenity --entry --title "Display Live Stream" --text "Enter target URL")
streamlink $url best
exit;;
$opt2 )
url=$(zenity --entry --title "Record Live Stream" --text "Enter target URL")
cd ~/Documents/Videos
streamlink $url best -o streamdata
open ~/Documents/Videos/
exit;;
$opt3 )
url=$(zenity --entry --title "Play and Record Live Stream" --text "Enter target URL")
cd ~/Documents/Videos
streamlink $url best -r streamdata
open ~/Documents/Videos/
exit;;
$opt4 )
zenity --info --text="The next window will prompt you for a local file which was previously recorded." --title="Stream Converter"
file=$(zenity --file-selection --title "Video Stream")
ffmpeg -i $file -c copy ~/Documents/Videos/stream.mp4
open ~/Documents/Videos/
exit;;
esac
done
